package com.zhongxin.wymovieticket.adapter;

import java.util.List;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.NetworkImageView;
import com.zhongxin.wymovie.widgte.RoundAngleImageView;
import com.zhongxin.wymovieticket.R;
import com.zhongxin.wymovieticketentity.HotMovies;
import com.zhoujing.utils.ImageDownLoad;
import com.zhoujing.utils.ImageDownLoadUtils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class ChangeModeImageAdapter extends BaseAdapter {

	private List<HotMovies> hotMovieslist;
	private Context context;
	private RequestQueue queue;

	public ChangeModeImageAdapter(List<HotMovies> hotMovies,
			RequestQueue queue, Context context) {
		// TODO Auto-generated constructor stub
		this.hotMovieslist = hotMovies;
		this.context = context;
		this.queue = queue;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return hotMovieslist.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return hotMovieslist.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.fragment_changemode_itemimage, parent, false);

			viewHolder.hotmovie_image = (RoundAngleImageView) convertView
					.findViewById(R.id.fragment_changemode_image);
			viewHolder.hotmovie_name = (TextView) convertView
					.findViewById(R.id.fragment_changemode_moviename);
			viewHolder.hotmovie_isnewmovie = (ImageView) convertView
					.findViewById(R.id.fragment_changemode_isnewtag);
			viewHolder.hotmovie_grade = (TextView) convertView
					.findViewById(R.id.fragment_changemode_grade);
			viewHolder.hotmovie_screenings = (TextView) convertView
					.findViewById(R.id.fragment_changemode_allscreens);
			viewHolder.hotmovie_buyticket = (Button) convertView
					.findViewById(R.id.fragment_changemode_buyticket);
			viewHolder.hotmovie_imagetag = (ImageView) convertView
					.findViewById(R.id.fragment_changemode_imagetag);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.hotmovie_name.setText(hotMovieslist.get(position).getName());
		if (hotMovieslist.get(position).getIsNew() == 1) {
			viewHolder.hotmovie_isnewmovie
					.setBackgroundResource(R.drawable.icon_new_tag);
		} else {

		}
		if (hotMovieslist.get(position).getDimensional().equals("3D,IMAX")) {
			viewHolder.hotmovie_imagetag
					.setBackgroundResource(R.drawable.icon_type_3dimax);
		} else if (hotMovieslist.get(position).getDimensional().equals("3D")) {
			viewHolder.hotmovie_imagetag
					.setBackgroundResource(R.drawable.icon_type_3d);
		} else if (hotMovieslist.get(position).getDimensional()
				.equals("2D,IMAX")) {
			viewHolder.hotmovie_imagetag
					.setBackgroundResource(R.drawable.icon_type_2dimax);
		}

		viewHolder.hotmovie_grade.setText(""
				+ hotMovieslist.get(position).getGrade() + "分");

		viewHolder.hotmovie_screenings.setText(hotMovieslist.get(position)
				.getScreenings());
		if (hotMovieslist.get(position).getLogo2() != null) {
			ImageDownLoadUtils.downLoadImage(hotMovieslist.get(position)
					.getLogo556640(), queue, context, viewHolder.hotmovie_image);
		} else {
			System.out.println("----------------------"
					+ hotMovieslist.get(position).getLogo2());
		}

		return convertView;
	}

	private static class ViewHolder {
		RoundAngleImageView hotmovie_image;
		TextView hotmovie_name;
		ImageView hotmovie_isnewmovie;
		ImageView hotmovie_imagetag;
		TextView hotmovie_grade;
		TextView hotmovie_highlight;
		TextView hotmovie_screenings;
		Button hotmovie_buyticket;

	}

}
